package cn.edu.imust.loginregisterdemo.home.view;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import java.nio.charset.Charset;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.edu.imust.loginregisterdemo.BuildConfig;
import cn.edu.imust.loginregisterdemo.R;
import cn.edu.imust.loginregisterdemo.home.model.domain.DownDataResult;

public class DetailActivity extends AppCompatActivity {


    @BindView(R.id.tv_upload_time)
    TextView tvUploadTime;
    @BindView(R.id.tv_height)
    TextView tvHeight;
    @BindView(R.id.tv_hash)
    TextView tvHash;
    @BindView(R.id.tv_previousHash)
    TextView tvPreviousHash;
    @BindView(R.id.tv_transactionSetHash)
    TextView tvTransactionSetHash;
    @BindView(R.id.tv_ledgerHash)
    TextView tvLedgerHash;
    @BindView(R.id.tv_userAccountSetHash)
    TextView tvUserAccountSetHash;
    @BindView(R.id.tv_adminAccountHash)
    TextView tvAdminAccountHash;
    @BindView(R.id.tv_dataAccountSetHash)
    TextView tvDataAccountSetHash;
    private DownDataResult.DataBean    dataBean;
    private String time;               //上传时间
    private int    height;             //区块高度
    private String hash;               //区块哈希
    private String previousHash;       //前置区块哈希
    private String transactionSetHash; //交易集哈希
    private String ledgerHash;         //账本哈希
    private String userAccountSetHash; //用户集哈希
    private String adminAccountHash;   //配置哈希
    private String dataAccountSetHash; //数据账户集哈希

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);
        ButterKnife.bind(this);

        initData();


    }

    /**
     * 初始化数据
     */
    private void initData() {
        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        if (bundle != null) {
            dataBean = (DownDataResult.DataBean) bundle.get("dataBean");
            if (dataBean != null) {
                getData();
                if (BuildConfig.DEBUG) Log.d("DetailActivity", "time-->" + time);
                tvUploadTime.setText(time);
                if (BuildConfig.DEBUG) Log.d("DetailActivity", "height-->" + height);
                tvHeight.setText(String.valueOf(height));
                if (BuildConfig.DEBUG) Log.d("DetailActivity", "hash-->" + hash);
                tvHash.setText(hash);
                if (BuildConfig.DEBUG) Log.d("DetailActivity", "previousHash-->" + previousHash);
                tvPreviousHash.setText(previousHash);
                if (BuildConfig.DEBUG) Log.d("DetailActivity", "transactionSetHash-->" + transactionSetHash);
                tvTransactionSetHash.setText(transactionSetHash);
                if (BuildConfig.DEBUG) Log.d("DetailActivity", "ledgerHash-->" + ledgerHash);
                tvLedgerHash.setText(ledgerHash);
                if (BuildConfig.DEBUG) Log.d("DetailActivity", "userAccountSetHash-->" + userAccountSetHash);
                tvUserAccountSetHash.setText(userAccountSetHash);
                if (BuildConfig.DEBUG) Log.d("DetailActivity", "adminAccountHash-->" + adminAccountHash);
                tvAdminAccountHash.setText(adminAccountHash);
                if (BuildConfig.DEBUG) Log.d("DetailActivity", "dataAccountSetHash-->" + dataAccountSetHash);
                tvDataAccountSetHash.setText(dataAccountSetHash);
            }
        }
    }

    /**
     * 拿到数据
     */
    private void getData() {
        time = dataBean.getTime();
        height = dataBean.getHeight();
        hash = dataBean.getHash().getValue();
        previousHash = dataBean.getPreviousHash().getValue();
        transactionSetHash = dataBean.getTransactionSetHash().getValue();
        ledgerHash = dataBean.getLedgerHash().getValue();
        userAccountSetHash = dataBean.getUserAccountSetHash().getValue();
        adminAccountHash = dataBean.getAdminAccountHash().getValue();
        dataAccountSetHash = dataBean.getDataAccountSetHash().getValue();
    }


}
